package com.invengo.library_rfid.classify;

import java.util.Arrays;
import java.util.List;

import java8.util.Optional;
import me.goldze.mvvmhabit.utils.cache.ACache;
import me.goldze.mvvmhabit.utils.cache.AKey;

public enum RfidModelImpl implements IRfidModel {
    TID("TID模式") {
        @Override
        public String apply(String tagMessage) {
            return tagMessage;
        }
    },
    EPC("EPC模式") {
        @Override
        public String apply(String tagMessage) {
            return tagMessage;
        }
    },
    U_DATA("UDATA模式") {
        @Override
        public String apply(String tagMessage) {
            return tagMessage;
        }
    };
    private String name;

    RfidModelImpl(String name) {
        this.name = name;
    }


    public static List<RfidModelImpl> getModelList() {
        return Arrays.asList(RfidModelImpl.values());
    }

    public String getName() {
        return name;
    }


    public static RfidModelImpl getDefaultModel() {
        RfidModelImpl model = (RfidModelImpl) ACache.getInstance().getAsObject(AKey.RFID_TAG_MODEL);
        if (model == null)
            model = RfidModelImpl.TID;
        return model;
    }

    public static int getPosition() {
        RfidModelImpl defaultModel = getDefaultModel();
        for (int i = 0; i < RfidModelImpl.values().length; i++) {
            if (defaultModel == RfidModelImpl.values()[i])
                return i;
        }
        throw new IllegalArgumentException("找不到角标。。。。");
    }

    public static void changeModel(int position) {
        ACache.getInstance().put(AKey.RFID_TAG_MODEL, getModelList().get(position));
    }


}
